<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script>
	<title>浏览器定位</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
	// 百度地图API功能
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(116.331398,39.897445);
	map.centerAndZoom(point,12);

	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var mk = new BMap.Marker(r.point);
			map.addOverlay(mk);
			map.panTo(r.point);
			alert('您的位置：'+r.point.lng+','+r.point.lat);
		}
		else {
			alert('failed'+this.getStatus());
		}
	},{enableHighAccuracy: true})
	//关于状态码
	//BMAP_STATUS_SUCCESS	检索成功。对应数值“0”。
	//BMAP_STATUS_CITY_LIST	城市列表。对应数值“1”。
	//BMAP_STATUS_UNKNOWN_LOCATION	位置结果未知。对应数值“2”。
	//BMAP_STATUS_UNKNOWN_ROUTE	导航结果未知。对应数值“3”。
	//BMAP_STATUS_INVALID_KEY	非法密钥。对应数值“4”。
	//BMAP_STATUS_INVALID_REQUEST	非法请求。对应数值“5”。
	//BMAP_STATUS_PERMISSION_DENIED	没有权限。对应数值“6”。(自 1.1 新增)
	//BMAP_STATUS_SERVICE_UNAVAILABLE	服务不可用。对应数值“7”。(自 1.1 新增)
	//BMAP_STATUS_TIMEOUT	超时。对应数值“8”。(自 1.1 新增)


    var mp = new BMap.Map('content');
    mp.enableScrollWheelZoom();//地图随鼠标滑轮滚动放大缩小的功能
    var mypoint = new BMap.Point(117.339937, 31.870068);//定义一个坐标对象
    //初始化地图的中心位置
    mp.centerAndZoom(mypoint, 14);   //第二个参数代表地图的放大级数，目前是1-18
    var opt1 = {type: BMAP_NAVIGATION_CONTROL_LARGE}     //导航控件样式
    mp.addControl(new BMap.NavigationControl(opt1));
    mp.addControl(new BMap.OverviewMapControl());         //略缩图控件
    mp.addControl(new BMap.ScaleControl({offset: new BMap.Size(75, 500)}));
    //比例尺控件
    mp.addControl(new BMap.MapTypeControl());
    mp.clearOverlays();//清除地图上的覆盖物
    var apolygon_points = new Array();
    apolygon_points.push(new BMap.Point(30.7381241085,120.7199996710));
    apolygon_points.push(new BMap.Point(30.7377137479,120.7203054428));
    apolygon_points.push(new BMap.Point(30.7377275803,120.7195168734));
    var apolygon = new BMap.Polygon(apolygon_points, {
        strokeColor: "red",
        strokeWeight: 2,
        strokeOpacity: 0.5,
        fillOpacity: 0.4
    });
    mp.addOverlay(apolygon);
    var opt = {position: new BMap.Point(117.338937, 31.880068), offset: new BMap.Size(0, 0)};
    var lname = "金庸图书馆"
    var label = new BMap.Label(lname, opt);
    mp.addOverlay(label);
    var msg = "";
    var pt = new BMap.Point(117.338937, 31.860068);
    mp.addOverlay(new BMap.Marker(pt));
    if (BMapLib.GeoUtils.isPointInPolygon(pt, apolygon)) {//如果点在区域内，返回true
        mp.addOverlay(new BMap.Marker(pt));
        msg = "在" + lname + "区域内";
    }
    else {
        mp.addOverlay(new BMap.Marker(pt));
        msg = "在" + lname + "区域外";
    }
    var label2 = new BMap.Label(msg, {position: pt, offset: new BMap.Size(0, 0)});
    mp.addOverlay(label2);




</script>
